/**
 * 
 */
package vn.edu.hungvuongaptech.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import vn.edu.hungvuongaptech.common.Constant;
import vn.edu.hungvuongaptech.model.ProcessModel;
import vn.edu.hungvuongaptech.util.DataUtil;

/**
 * @author PCHOME
 *
 */
public class ProcessDAO {
	public static ArrayList<ProcessModel> getAllProcess(){
		ArrayList<ProcessModel> processModelList = new ArrayList<ProcessModel>();
		try {
			String sql = Constant.SQL_RES.getString("timesheet.sql.getAllProcess");
			ResultSet rs = DataUtil.executeQuery(sql);
			ProcessModel processModel = null;
			while (rs.next()) {
				processModel = new ProcessModel();
				processModel.setProcessId(rs.getInt("ProcessId"));
				processModel.setProcessName(rs.getString("ProcessName"));
				processModel.setProcessDescription(rs.getString("ProcessDescription"));
				processModelList.add(processModel);
			}
			return processModelList;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static ProcessModel getProcessByID(int processID){
		ProcessModel processModel = new ProcessModel();		
		try {
			PreparedStatement preparedStatement = DataUtil
					.getConnection()
					.prepareStatement(
							Constant.SQL_RES
									.getString("timesheet.sql.getProcessByID"));
			preparedStatement.setLong(1, processID);
			ResultSet rs = preparedStatement.executeQuery();
			while (rs.next()) {
				processModel.setProcessId(rs.getInt("ProcessID"));
				processModel.setProcessName(rs.getString("ProcessName"));
				processModel.setProcessDescription(rs.getString("ProcessDescription"));
			}
			return processModel;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
